#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define MY_RAND_MAX 2147483647

/* Felipe Osorio Thomé
   Simple linear congruential generator. */
int my_rand(unsigned int *seed)
{
    unsigned int next;
    next = *seed;
    next = next * 1103515245 + 12345;
    next = next % (1<<31);

    return *seed = next;
}

/* Reentrant random function from POSIX.1c.
   Copyright (C) 1996, 1999, 2009 Free Software Foundation, Inc.
   This functin is part of the GNU C Library.
   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. */
int old_gnu_rand_r (unsigned int *seed)
{
    unsigned int next = *seed;
    int result;

    next *= 1103515245;
    next += 12345;
    result = (unsigned int) (next / 65536) % 2048;

    next *= 1103515245;
    next += 12345;
    result <<= 10;
    result ^= (unsigned int) (next / 65536) % 1024;

    next *= 1103515245;
    next += 12345;
    result <<= 10;
    result ^= (unsigned int) (next / 65536) % 1024;

    *seed = next;

    return result;
}

int main()
{
    int i;
    unsigned int x = time(NULL);

    for(i = 0; i < 10; i++)
    {
        printf("\n%lf", ((double) my_rand(&x)) / MY_RAND_MAX);
    }

    printf("\n\n\n");

    for(i = 0; i < 10; i++)
    {
        printf("\n%lf", ((double) old_gnu_rand_r(&x)) / MY_RAND_MAX);
    }

    return 0;
}
